
#pragma once

#include <ddraw.h>
#include "sglrender.h"
#include "sgldecode.h"

class DDrawRender : public SglRender
{

public:

	DDrawRender();
	virtual ~DDrawRender();

	HRESULT GetResult(VOID) const;

	virtual BOOL Create(HWND hWnd, INT nWidth, INT nHeight, BOOL bFullScreen);
	virtual BOOL BeginDraw();
	virtual BOOL Draw(PBUFFER pBuffer, COLORREF dwBgColor);
	virtual BOOL EndDraw();
	virtual BOOL DrawPixel(INT nX, INT nY, COLORREF dwColor, BYTE byAlpha);
	virtual BOOL Render(LPCRECT pRect);
	virtual VOID Destroy(VOID);

private:

	HWND					m_Wnd;
	HRESULT					m_Result;
	UINT					m_BgWidth;
	UINT					m_BgHeight;
	SIZE					m_Size;
	LPDIRECTDRAW7			m_DDraw;
	LPDIRECTDRAWSURFACE7	m_DDSPrimary;
	LPDIRECTDRAWSURFACE7	m_DDSBackground;
	LPDIRECTDRAWSURFACE7	m_DDSCanvas;

	BOOL CheckCapability(LPDIRECTDRAW7 pDDraw);
	BOOL CleanUp(VOID);
	BOOL ClearDraw(VOID);
	BOOL AttachWindow(HWND hWnd, INT nWidth, INT nHeight);
	BOOL DetachWindow(VOID);
	BOOL ClipWindow(LPDIRECTDRAWSURFACE7 pDDS, HWND hWnd);
	BOOL RestoreSurface(LPDIRECTDRAWSURFACE7 pDDS);
	BOOL AdjustBgSurface(UINT nWidth, UINT nHeight);
	BOOL CreateBgSurface(UINT nWidth, UINT nHeight);
	BOOL CreateCanvasSurface(UINT nWidth, UINT nHeight);
	BOOL DrawBuffer(PBUFFER pBuffer, COLORREF dwBgColor);
	BOOL DrawBlock(PBLOCK pBlock, LPRECT pRect, COLORREF dwBgColor);
	BOOL DrawEmpty(PBLOCK pBlock, LPRECT pRect);
	BOOL DrawDXT1(PBLOCK pBlock, LPRECT pRect);
	BOOL DrawDXT3(PBLOCK pBlock, LPRECT pRect);
	BOOL DrawTexture(DWORD dwFourCC, PBLOCK pBlock, LPRECT pRect);
	BOOL AlphaBlend(PBLOCK pBlock, LPRECT pRect, COLORREF dwBgColor);
	BOOL AlphaBlend(LPDDSURFACEDESC2 pDDSDesc, PBLOCK pBlock, COLORREF dwBgColor);
	BOOL FlipToBackgroundRect(UINT nX, UINT nY, UINT nWidth, UINT nHeight);
	BOOL FlipToBackground(UINT nWidth, UINT nHeight);
	BOOL FlipToBackground(LPDDSURFACEDESC2 pDDSDesc, UINT nLineNum, UINT nX = 0, UINT nY = 0);
	BOOL ConvertPixelForamt(HDC hDC, LPCVOID pData, INT nWidth, INT nHeight);

};
